package com.stox.ui.javafx.core.event.handler;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;

public abstract class AbstractPropertyChangeListener<T> implements ChangeListener<T> {

	private Node node;
	private boolean locked;
	
	public AbstractPropertyChangeListener(Node node) {
		this.node = node;
	}
	
	@Override
	public void changed(ObservableValue<? extends T> arg0, T oldValue, T newValue) {
		if(locked || oldValue.equals(newValue)) return;
		try {
			locked = true;
			changed(newValue, node);
		}finally {
			locked = false;
		}
	}
	
	public abstract void changed(T newValue, Node node);
	
}
